#include <JXQCore/JXQGlobal>
#if defined(J_OS_UNIX) || defined(J_OS_LINUX)

#include "jabstractio_p.h"
#include <unistd.h>
#include <signal.h>

namespace JXQ
{

} //namespace JXQ

/*------------------------------------------------------------------------------------------------*/

static __sighandler_t gPreHandler = nullptr;

static void signalHandler(int signo)
{
	if( signo == SIGPIPE )
		jError() << "ERROR(from JXQLIB): SIGPIPE(13)!!!";

	if( gPreHandler != nullptr )
		gPreHandler(signo);
}

static int filter_SIGPIPE()
{
	auto pre = ::signal(SIGPIPE, signalHandler);
	if( pre == SIG_ERR )
		jError() << "ERROR(from JXQLIB): The process could not register signal 'SIGPIPE(13)'";
	else
		gPreHandler = pre;
	return 0;
}
volatile int __filter_SIGPIPE__ J_DECL_UNUSED = filter_SIGPIPE();


#endif // unix/linux
